package server.Example;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import server.jdbc.DAOUtil;
import server.utils.AbsAsyncQueryDb;
import server.utils.AppFile;

import com.core.async.AsyncServiceImpl;
import com.core.async.IAsyncService;
import com.core.interfaces.IMessageExecutorPool;
import com.core.thread.OneMessageExecutorPool;

public class AsyncQueryExample implements Runnable
{
	
	/**异步线程回调服务**/
	public static IAsyncService asyncService = new AsyncServiceImpl();

	public static void main(String[] args)
	{
		File f = new File(System.getProperty("user.dir"));
		String path = f.getPath() + File.separator + "src" + File.separator
				+ "main" + File.separator + "resources"+File.separator+"config";
		AppFile.path=path;
		//初始化数据库
		DAOUtil.getInstance();
		IMessageExecutorPool pool = new OneMessageExecutorPool();
		asyncService.init(pool, 10);
		AsyncQueryExample example = new AsyncQueryExample();
		pool.pushAction(example);
		
	}

	@Override
	public void run() {
		List list = new ArrayList();
		list.add("makcy");
		try {
			SyncQuery query = new SyncQuery("select * from user where account= ?", list);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	
	class SyncQuery extends AbsAsyncQueryDb {

		public SyncQuery(String sql, List params) throws Exception {
			super(sql, params);
			query(sql, params);
			doCallBack();
		}

		@Override
		protected void queryBack() {
			System.out.println();		
		}
	}
}
